namespace graver.CodeAnalysis.Syntax;

/// <summary>
/// 语法树
/// </summary>
public sealed class SyntaxTree
{
    public SyntaxTree(IEnumerable<string> diagnostics, ExpressionSyntax root, SyntaxToken endOfFileToken)
    {
        Diagnostics = diagnostics.ToArray();
        Root = root;
        EndOfFileToken = endOfFileToken;
    }

    /// <summary>
    /// 诊断信息
    /// </summary>
    public IReadOnlyList<string> Diagnostics { get; }

    /// <summary>
    /// 根节点
    /// </summary>
    public ExpressionSyntax Root { get; }

    /// <summary>
    /// 结束标记
    /// </summary>
    public SyntaxToken EndOfFileToken { get; }

    /// <summary>
    /// 解析输入
    /// </summary>
    /// <param name="text">输入的表达式字符串</param>
    /// <returns>解析后的语法树</returns>
    public static SyntaxTree Parse(string text)
    {
        var parser = new Parser(text);
        return parser.Parse();
    }
}
